/**
 * App组件测试
 */

import { describe, it, expect, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import { BrowserRouter } from 'react-router-dom'
import App from '../App'

// Mock React Query
vi.mock('react-query', () => ({
  QueryClient: vi.fn(() => ({
    setDefaultOptions: vi.fn(),
  })),
  QueryClientProvider: ({ children }: { children: React.ReactNode }) => children,
  ReactQueryDevtools: () => null,
}))

// Mock store
vi.mock('@/store', () => ({
  useUserStore: () => ({
    isAuthenticated: false,
    user: null,
    token: null,
    setUser: vi.fn(),
    logout: vi.fn(),
  }),
  useSettingsStore: () => ({
    theme: 'light',
    language: 'zh-CN',
    sidebarCollapsed: false,
    autoRefreshInterval: 30,
    showDebugInfo: false,
    updateSettings: vi.fn(),
    toggleTheme: vi.fn(),
    toggleSidebar: vi.fn(),
  }),
}))

describe('App', () => {
  beforeEach(() => {
    // 清理localStorage
    localStorage.clear()
  })

  it('应该渲染登录页面当用户未认证时', () => {
    render(
      <BrowserRouter>
        <App />
      </BrowserRouter>
    )

    // 应该重定向到登录页面
    expect(window.location.pathname).toBe('/')
  })

  it('应该应用正确的主题类', () => {
    render(
      <BrowserRouter>
        <App />
      </BrowserRouter>
    )

    // 检查根元素是否有正确的类名
    const root = document.documentElement
    expect(root.classList.contains('light')).toBe(true)
  })
})
